'use strict';

const Controller = require('egg').Controller;

class MyController extends Controller {
    //我的消费
    async consume() {
        const { ctx, app } = this
        const uid = ctx.wxUser.id
        let list = await ctx.page(app.model.Consume,
            {
                wx_user_id: uid
            })
        ctx.apiSuccess(list)
    }
    //意见反馈 列表
    async feelist(){
        const {ctx,app}=this
        const uid=ctx.wxUser.id
        let list= await ctx.page(app.model.Feedback,{wx_id: uid})
        ctx.apiSuccess(list)
    }
    //意见反馈 提交
    async feeadd(){
        const {ctx,app}=this
        const user=ctx.wxUser
        ctx.validate({
            type:{
                type:'string',
                required:true,
                desc:'类型'
            },
            content:{
                type:'string',
                required:true,
                desc:'内容'
            },
            images:{
                type:'string',
                required:false,
                desc:'图片'
            }
        })
        const {type,content,images}=ctx.request.body
        let list=await app.model.Feedback.create({
            wx_id:user.id,
            wxname:user.nickname,
            type,
            content,
            images
        })
        if(!list){
            ctx.throw(400,'创建失败')
        }
        ctx.apiSuccess('创建成功')
    }
    //常见问题  关于我们
    async filelist(){
        const {ctx,app}=this;
        const {type}=ctx.query
        ctx.validate({
            type:{
                type:'string',
                required:true,
                desc:'类型'
            }
        })
        let list= await ctx.page(app.model.File,{type})
        ctx.apiSuccess(list)
    }
}

module.exports = MyController;
